using System.Linq.Expressions;
using Rogan.Utility.Linq;

namespace Rogan.Data.Linq
{
	public class DbQueryProvider<T> : QueryProvider where T : Entity
	{
		private EntityQueryable<T> entityQuery;
		public DbQueryProvider(EntityQueryable<T> entityQuery)
		{
			this.entityQuery = entityQuery;
		}
		public override object Execute(Expression expression)
		{
			ExpressionTranslater<T> expressionTranslater = new ExpressionTranslater<T>(expression, entityQuery);
			expressionTranslater.Translat();
			return expressionTranslater.Execute();
		}
		public override string GetQueryText(Expression expression)
		{
			ExpressionTranslater<T> expressionTranslater = new ExpressionTranslater<T>(expression, entityQuery);
			expressionTranslater.Translat();
			ExpressionTranslater expressionTranslater2 = new ExpressionTranslater(entityQuery.DbProvider, expressionTranslater.EntityQueryExpression);
			expressionTranslater2.Translate();
			return expressionTranslater2.CommandText;
		}
	}
}
